<template>
	<view>
		<view class="box" @click="show = true">
			<view class="">
				项目分类：
			</view>
			<view class="" v-if="classselect == false">
				点击选择分类
			</view>
			<view class="" v-if="classselect == true">
				{{classlist[classindex].classifyName}}
			</view>
		</view>
		<view class="box">
			<view class="">
				项目名称：
			</view>
			<view class="input">
				<input type="text" v-model="project.name" placeholder="新增项目名称" />
			</view>
		</view>
		<view class="boxs">
			<view class="">
				项目图片：
			</view>
			<view class="addimg" @click="addimage">
				<view class="" v-if="project.image.length>0">
					<image :src="project.image" mode=""></image>
				</view>
				<view class="" v-if="project.image.length<=0">
					+
				</view>
			</view>
		</view>
		<view class="box">
			<view class="">
				项目时长：
			</view>
			<view class="input">
				<input type="text" v-model="project.duration" placeholder="请输入项目时长" />
			</view>
		</view>

		<view class="box">
			<view class="">
				项目价格：
			</view>
			<view class="input">
				<input type="number" v-model="" placeholder="请输入价格" />
			</view>
			<view class="" style="margin-left: 20rpx;">
				元
			</view>
		</view>
		<view class="boxs">
			<view class="">
				适用人群：
			</view>
			<view class="addimg">
				<textarea type="text" v-model="project.fitCrowd" placeholder="请输入适用人群" />
			</view>
		</view>
		<view class="boxs">
			<view class="">
				项目介绍：
			</view>
			<view class="addimg">
				<textarea value="" v-model="project.projectIntroduce" placeholder="请输入内容" />
			</view>
		</view>
		<view class="boxs">
			<view class="">
				禁忌人群：
			</view>
			<view class="addimg">
				<textarea value="" v-model="project.tabooCrowd" placeholder="请输入内容" />
			</view>
		</view>
		<view class="boxs">
			<view class="">
				调理流程：
			</view>
			<view class="addimg">
				<textarea value="" v-model="project.projectProcess" placeholder="请输入内容" />
			</view>
		</view>
		<view class="boxs">
			<view class="">
				保养方法：
			</view>
			<view class="addimg">
				<textarea value="" v-model="project.maintainMethod" placeholder="请输入内容" />
			</view>
		</view>

		<u-picker v-model="show" mode="selector" :default-selector="[0]" :range="classlist" range-key="classifyName"
			@confirm="selectclass"></u-picker>
		<view class="button" @click="addproject">
			新增
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				classlist: [], //分类列表
				classindex: '', //选择的分类下标
				classselect: false,
				project: {
					"classifyId": "", //按摩项目分类id
					"classifyName": "", //按摩项目分类名称
					"duration": "", //项目时长
					"fitCrowd": "", //适用人群
					"image": "", //项目图片
					"maintainMethod": "", //保养方法
					"name": "", //项目名称
					"projectIntroduce": "", //项目介绍
					"projectProcess": "", //调理流程
					"storeId": 0, //按摩项目的店铺id
					"tabooCrowd": "" //禁忌人群
				}, //项目准备数据
			}
		},
		onLoad() {
			this.getclasslist()
		},
		methods: {
			//条件判断
			conditionjudge() {
				if (this.project.classifyName.length <= 0) {
					uni.showToast({
						title:"请选择分类"
					})
					return false
				}
				if (this.project.name.length <= 0) {
					uni.showToast({
						title:"请选输入项目名称"
					})
					return false
				}
				if (this.project.image.length <= 0) {
					uni.showToast({
						title:"请选择项目图片"
					})
					return false
				}
				if (this.project.duration.length <= 0) {
					uni.showToast({
						title:"请输入项目时长"
					})
					return false
				}
				if (this.project.duration.length <= 0) {
					uni.showToast({
						title:"请输入项目时长"
					})
					return false
				}
			},
			//新增项目
			addproject() {

			},
			//选择图片
			addimage() {
				var that = this
				uni.chooseImage({
					count: 1, //默认9
					success: function(res) {
						console.log(res.tempFilePaths[0]);
						that.project.image = res.tempFilePaths[0]
					}
				});
			},
			//选择分类
			selectclass(e) {
				this.classindex = e[0]
				this.classselect = true
				console.log('选择', this.classlist[this.classindex].classifyName)
				this.project.classifyId = this.classlist[this.classindex].classifyId
				this.project.classifyName = this.classlist[this.classindex].classifyName
			},
			// 获取分类
			getclasslist() {
				var that = this
				var data = {}
				that.$http("/api/user/store/classifyList/" + 1, 'GET', data).then((res) => {
					console.log('分类', res.data.data.list)
					that.classlist = res.data.data.list
				})
			},
		}
	}
</script>

<style lang="scss">
	image {
		width: 100%;
		height: 100%;
	}

	.box {
		padding: 20rpx;
		border-bottom: 1rpx solid #ECECEC;
		display: flex;
		align-items: center;

		.input {
			border: 1rpx solid #ECECEC;
			flex: 0 0 40%;
			padding: 4rpx 10rpx;
			border-radius: 10rpx;
		}

	}

	.boxs {
		padding: 20rpx;

		.addimg {
			border-bottom: 1rpx solid #ECECEC;

			textarea {
				width: 90%;
				height: 300rpx;
				border: 1rpx solid #ECECEC;
				border-radius: 10rpx;
				padding: 20rpx;
				margin: 20rpx auto;
			}

			view {
				width: 180rpx;
				height: 180rpx;
				border: 1rpx solid #ECECEC;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 50rpx;
				margin: 20rpx;
			}
		}
	}

	.button {
		background-color: #F39E1C;
		color: #FFFFFF;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
	}
</style>
